home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / xfonts-utils.postinst < prev    next >
Encoding:
Text File  |  2006-12-18  |  29.9 KB  |  930 lines

  1. #! /bin/sh
  2.  
  3. set -e
  4.  
  5. THIS_PACKAGE=xfonts-utils
  6. THIS_SCRIPT=postinst
  7.  
  8. # $Id: xsfbs.sh 2888 2006-08-22 03:04:13Z dnusinow $
  9.  
  10. # This is the X Strike Force shell library for X Window System package
  11. # maintainer scripts.  It serves to define shell functions commonly used by
  12. # such packages, and performs some error checking necessary for proper operation
  13. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  14. # invoke the functions defined here to accomplish package installation and
  15. # removal tasks.
  16.  
  17. # If you are reading this within a Debian package maintainer script (e.g.,
  18. # /var/lib/dpkg)info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  19. # skip past this library by scanning forward in this file to the string
  20. # "GOBSTOPPER".
  21.  
  22. SOURCE_VERSION=1:1.0.1-1ubuntu1
  23. OFFICIAL_BUILD=
  24.  
  25. # Use special abnormal exit codes so that problems with this library are more
  26. # easily tracked down.
  27. SHELL_LIB_INTERNAL_ERROR=86
  28. SHELL_LIB_THROWN_ERROR=74
  29. SHELL_LIB_USAGE_ERROR=99
  30.  
  31. # old -> new variable names
  32. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  33.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  34. fi
  35. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  36.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  37. fi
  38.  
  39. # initial sanity checks
  40. if [ -z "$THIS_PACKAGE" ]; then
  41.   cat >&2 <<EOF
  42. Error: package maintainer script attempted to use shell library without
  43. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  44. version, and the text of this error message to the Debian Bug Tracking System.
  45. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  46. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  47. "doc-debian" package, or install the "reportbug" package and use the command of
  48. the same name to file a report against version $SOURCE_VERSION of this package.
  49. EOF
  50.   exit $SHELL_LIB_USAGE_ERROR
  51. fi
  52.  
  53. if [ -z "$THIS_SCRIPT" ]; then
  54.   cat >&2 <<EOF
  55. Error: package maintainer script attempted to use shell library without
  56. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  57. version, and the text of this error message to the Debian Bug Tracking System.
  58. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  59. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  60. "doc-debian" package, or install the "reportbug" package and use the command of
  61. the same name to file a report against version $SOURCE_VERSION of the
  62. "$THIS_PACKAGE" package.
  63. EOF
  64.   exit $SHELL_LIB_USAGE_ERROR
  65. fi
  66.  
  67. ARCHITECTURE="$(dpkg --print-installation-architecture)"
  68.  
  69. LAPTOP=""
  70. if [ -n "$(which laptop-detect)" ]; then
  71.     if laptop-detect >/dev/null; then
  72.     LAPTOP=true
  73.     fi
  74. fi
  75.  
  76. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  77.   RECONFIGURE="true"
  78. else
  79.   RECONFIGURE=
  80. fi
  81.  
  82. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  83.   FIRSTINST="yes"
  84. fi
  85.  
  86. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  87.   UPGRADE="yes"
  88. fi
  89.  
  90. trap "message;\
  91.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  92.       message;\
  93.       exit 1" HUP INT QUIT TERM
  94.  
  95. reject_nondigits () {
  96.   # syntax: reject_nondigits [ operand ... ]
  97.   #
  98.   # scan operands (typically shell variables whose values cannot be trusted) for
  99.   # characters other than decimal digits and barf if any are found
  100.   while [ -n "$1" ]; do
  101.     # does the operand contain anything but digits?
  102.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  103.       # can't use die(), because it wraps message() which wraps this function
  104.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  105.            "possibly malicious garbage \"$1\"" >&2
  106.       exit $SHELL_LIB_THROWN_ERROR
  107.     fi
  108.     shift
  109.   done
  110. }
  111.  
  112. reject_whitespace () {
  113.   # syntax: reject_whitespace [ operand ]
  114.   #
  115.   # scan operand (typically a shell variable whose value cannot be trusted) for
  116.   # whitespace characters and barf if any are found
  117.   if [ -n "$1" ]; then
  118.     # does the operand contain any whitespace?
  119.     if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
  120.       # can't use die(), because I want to avoid forward references
  121.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
  122.            "possibly malicious garbage \"$1\"" >&2
  123.       exit $SHELL_LIB_THROWN_ERROR
  124.     fi
  125.   fi
  126. }
  127.  
  128. reject_unlikely_path_chars () {
  129.   # syntax: reject_unlikely_path_chars [ operand ... ]
  130.   #
  131.   # scan operands (typically shell variables whose values cannot be trusted) for
  132.   # characters unlikely to be seen in a path and which the shell might
  133.   # interpret and barf if any are found
  134.   while [ -n "$1" ]; do
  135.     # does the operand contain any funny characters?
  136.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  137.       # can't use die(), because I want to avoid forward references
  138.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  139.            "encountered possibly malicious garbage \"$1\"" >&2
  140.       exit $SHELL_LIB_THROWN_ERROR
  141.     fi
  142.     shift
  143.   done
  144. }
  145.  
  146. # Query the terminal to establish a default number of columns to use for
  147. # displaying messages to the user.  This is used only as a fallback in the
  148. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  149. # the script is running, and this cannot, only being calculated once.)
  150. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  151. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  152.   DEFCOLUMNS=80
  153. fi
  154.  
  155. message () {
  156.   # pretty-print messages of arbitrary length
  157.   reject_nondigits "$COLUMNS"
  158.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  159. }
  160.  
  161. observe () {
  162.   # syntax: observe message ...
  163.   #
  164.   # issue observational message suitable for logging someday when support for
  165.   # it exists in dpkg
  166.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  167.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  168.   fi
  169. }
  170.  
  171. warn () {
  172.   # syntax: warn message ...
  173.   #
  174.   # issue warning message suitable for logging someday when support for
  175.   # it exists in dpkg; also send to standard error
  176.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  177. }
  178.  
  179. die () {
  180.   # syntax: die message ...
  181.   #
  182.   # exit script with error message
  183.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  184.   exit $SHELL_LIB_THROWN_ERROR
  185. }
  186.  
  187. internal_error () {
  188.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  189.   message "internal error: $*"
  190.   if [ -n "$OFFICIAL_BUILD" ]; then
  191.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  192.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  193.             "Tracking System.  Include all messages above that mention the" \
  194.             "$THIS_PACKAGE package.  Visit " \
  195.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  196.             "instructions, read the file" \
  197.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  198.             "package, or install the reportbug package and use the command of" \
  199.             "the same name to file a report."
  200.   fi
  201.   exit $SHELL_LIB_INTERNAL_ERROR
  202. }
  203.  
  204. usage_error () {
  205.   message "usage error: $*"
  206.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  207.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  208.           "Tracking System.  Include all messages above that mention the" \
  209.           "$THIS_PACKAGE package.  Visit " \
  210.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  211.           "instructions, read the file" \
  212.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  213.           "package, or install the reportbug package and use the command of" \
  214.           "the same name to file a report."
  215.   exit $SHELL_LIB_USAGE_ERROR
  216. }
  217.  
  218.  
  219. maplink () {
  220.   # returns what symlink should point to; i.e., what the "sane" answer is
  221.   # Keep this in sync with the debian/*.links files.
  222.   # This is only needed for symlinks to directories.
  223.   #
  224.   # XXX: Most of these look wrong in the X11R7 world and need to be fixed.
  225.   # If we've stopped using this function, fixing it might enable us to re-enable
  226.   # it again and catch more errors.
  227.   case "$1" in
  228.     /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
  229.     /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
  230.     /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
  231.     /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
  232.     /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
  233.     /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
  234.     /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
  235.     /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
  236.     /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
  237.     /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
  238.     /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
  239.     /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
  240.     /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
  241.     /usr/bin/X11) echo ../X11R6/bin ;;
  242.     /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
  243.     /usr/include/X11) echo ../X11R6/include/X11 ;;
  244.     /usr/lib/X11) echo ../X11R6/lib/X11 ;;
  245.     *) internal_error "maplink() called with unknown path \"$1\"" ;;
  246.   esac
  247. }
  248.  
  249. analyze_path () {
  250.   # given a supplied set of pathnames, break each one up by directory and do an
  251.   # ls -dl on each component, cumulatively; i.e.
  252.   # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
  253.   # Thanks to Randolph Chung for this clever hack.
  254.  
  255.   #local f g
  256.  
  257.   while [ -n "$1" ]; do
  258.     reject_whitespace "$1"
  259.     _g=
  260.     message "Analyzing $1:"
  261.     for _f in $(echo "$1" | tr / \  ); do
  262.       if [ -e /$_g$_f ]; then
  263.         ls -dl /$_g$_f /$_g$_f.dpkg-* 2> /dev/null || true
  264.         _g=$_g$_f/
  265.       else
  266.         message "/$_g$_f: nonexistent; directory contents of /$_g:"
  267.         ls -l /$_g
  268.         break
  269.       fi
  270.     done
  271.     shift
  272.   done
  273. }
  274.  
  275. find_culprits () {
  276.   #local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
  277.   #  msg
  278.  
  279.   reject_whitespace "$1"
  280.   message "Searching for overlapping packages..."
  281.   _dpkg_info_dir=/var/lib/dpkg/info
  282.   if [ -d $_dpkg_info_dir ]; then
  283.     if [ "$(echo $_dpkg_info_dir/*.list)" != "$_dpkg_info_dir/*.list" ]; then
  284.       _possible_culprits=$(ls -1 $_dpkg_info_dir/*.list | egrep -v \
  285.         "(xbase-clients|x11-common|xfs|xlibs)")
  286.       if [ -n "$_possible_culprits" ]; then
  287.         _smoking_guns=$(grep -l "$1" $_possible_culprits || true)
  288.         if [ -n "$_smoking_guns" ]; then
  289.           _bad_packages=$(printf "\\n")
  290.           for f in $_smoking_guns; do
  291.             # too bad you can't nest parameter expansion voodoo
  292.             p=${f%*.list}      # strip off the trailing ".list"
  293.             _package=${p##*/}   # strip off the directories
  294.             _bad_packages=$(printf "%s\n%s" "$_bad_packages" "$_package")
  295.           done
  296.           _msg=$(cat <<EOF
  297. The following packages appear to have file overlaps with the X.Org packages;
  298. these packages are either very old, or in violation of Debian Policy.  Try
  299. upgrading each of these packages to the latest available version if possible:
  300. for example, with the command "apt-get install".  If no newer version of a
  301. package is available, you will have to remove it; for example, with the command
  302. "apt-get remove".  If even the latest available version of the package has
  303. this file overlap, please file a bug against that package with the Debian Bug
  304. Tracking System.  You may want to refer the package maintainer to section 12.8
  305. of the Debian Policy manual.
  306. EOF
  307. )
  308.           message "$_msg"
  309.           message "The overlapping packages are: $_bad_packages"
  310.         else
  311.           message "no overlaps found."
  312.         fi
  313.       fi
  314.     else
  315.       message "cannot search; no matches for $_dpkg_info_dir/*.list."
  316.     fi
  317.   else
  318.     message "cannot search; $_dpkg_info_dir does not exist."
  319.   fi
  320. }
  321.  
  322. # we require a readlink command or shell function
  323. if ! which readlink > /dev/null 2>&1; then
  324.   message "The readlink command was not found.  Please install version" \
  325.           "1.13.1 or later of the debianutils package."
  326.   readlink () {
  327.     # returns what symlink in $1 actually points to
  328.     perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
  329.   }
  330. fi
  331.  
  332. check_symlink () {
  333.   # syntax: check_symlink symlink
  334.   #
  335.   # See if specified symlink points where it is supposed to.  Return 0 if it
  336.   # does, and 1 if it does not.
  337.   #
  338.   # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
  339.  
  340.   #local symlink
  341.  
  342.   # validate arguments
  343.   if [ $# -ne 1 ]; then
  344.     usage_error "check_symlink() called with wrong number of arguments;" \
  345.                 "expected 1, got $#"
  346.     exit $SHELL_LIB_USAGE_ERROR
  347.   fi
  348.  
  349.   _symlink="$1"
  350.  
  351.   if [ "$(maplink "$_symlink")" = "$(readlink "$_symlink")" ]; then
  352.     return 0
  353.   else
  354.     return 1
  355.   fi
  356. }
  357.  
  358. check_symlinks_and_warn () {
  359.   # syntax: check_symlinks_and_warn symlink ...
  360.   #
  361.   # For each argument, check for symlink sanity, and warn if it isn't sane.
  362.   #
  363.   # Call this function from a preinst script in the event $1 is "upgrade" or
  364.   # "install".
  365.  
  366.   #local errmsg symlink
  367.  
  368.   # validate arguments
  369.   if [ $# -lt 1 ]; then
  370.     usage_error "check_symlinks_and_warn() called with wrong number of" \
  371.                 "arguments; expected at least 1, got $#"
  372.     exit $SHELL_LIB_USAGE_ERROR
  373.   fi
  374.  
  375.   while [ -n "$1" ]; do
  376.     _symlink="$1"
  377.     if [ -L "$_symlink" ]; then
  378.       if ! check_symlink "$_symlink"; then
  379.         observe "$_symlink symbolic link points to wrong location" \
  380.                 "$(readlink "$_symlink"); removing"
  381.         rm "$_symlink"
  382.       fi
  383.     elif [ -e "$_symlink" ]; then
  384.       _errmsg="$_symlink exists and is not a symbolic link; this package cannot"
  385.       _errmsg="$_errmsg be installed until this"
  386.       if [ -f "$_symlink" ]; then
  387.         _errmsg="$_errmsg file"
  388.       elif [ -d "$_symlink" ]; then
  389.         _errmsg="$_errmsg directory"
  390.       else
  391.         _errmsg="$_errmsg thing"
  392.       fi
  393.       _errmsg="$_errmsg is removed"
  394.       die "$_errmsg"
  395.     fi
  396.     shift
  397.   done
  398. }
  399.  
  400. check_symlinks_and_bomb () {
  401.   # syntax: check_symlinks_and_bomb symlink ...
  402.   #
  403.   # For each argument, check for symlink sanity, and bomb if it isn't sane.
  404.   #
  405.   # Call this function from a postinst script.
  406.  
  407.   #local problem symlink
  408.  
  409.   # validate arguments
  410.   if [ $# -lt 1 ]; then
  411.     usage_error "check_symlinks_and_bomb() called with wrong number of"
  412.                 "arguments; expected at least 1, got $#"
  413.     exit $SHELL_LIB_USAGE_ERROR
  414.   fi
  415.  
  416.   while [ -n "$1" ]; do
  417.     _problem=
  418.     _symlink="$1"
  419.     if [ -L "$_symlink" ]; then
  420.       if ! check_symlink "$_symlink"; then
  421.         _problem=yes
  422.         warn "$_symlink symbolic link points to wrong location" \
  423.              "$(readlink "$_symlink")"
  424.       fi
  425.     elif [ -e "$_symlink" ]; then
  426.       _problem=yes
  427.       warn "$_symlink is not a symbolic link"
  428.     else
  429.       _problem=yes
  430.       warn "$_symlink symbolic link does not exist"
  431.     fi
  432.     if [ -n "$_problem" ]; then
  433.       analyze_path "$_symlink" "$(readlink "$_symlink")"
  434.       find_culprits "$_symlink"
  435.       die "bad symbolic links on system"
  436.     fi
  437.     shift
  438.   done
  439. }
  440.  
  441. font_update () {
  442.   # run $UPDATECMDS in $FONTDIRS
  443.  
  444.   #local dir cmd shortcmd x_font_dir_prefix
  445.  
  446.   _x_font_dir_prefix="/usr/share/fonts/X11"
  447.  
  448.   if [ -z "$UPDATECMDS" ]; then
  449.     usage_error "font_update() called but \$UPDATECMDS not set"
  450.   fi
  451.   if [ -z "$FONTDIRS" ]; then
  452.     usage_error "font_update() called but \$FONTDIRS not set"
  453.   fi
  454.  
  455.   reject_unlikely_path_chars "$UPDATECMDS"
  456.   reject_unlikely_path_chars "$FONTDIRS"
  457.  
  458.   for _dir in $FONTDIRS; do
  459.     if [ -d "$_x_font_dir_prefix/$_dir" ]; then
  460.       for _cmd in $UPDATECMDS; do
  461.         if which "$_cmd" > /dev/null 2>&1; then
  462.           _shortcmd=${_cmd##*/}
  463.           observe "running $_shortcmd in $_dir font directory"
  464.       _cmd_opts=
  465.           if [ "$_shortcmd" = "update-fonts-alias" ]; then
  466.             _cmd_opts=--x11r7-layout
  467.           fi
  468.           if [ "$_shortcmd" = "update-fonts-dir" ]; then
  469.             _cmd_opts=--x11r7-layout
  470.           fi
  471.           if [ "$_shortcmd" = "update-fonts-scale" ]; then
  472.             _cmd_opts=--x11r7-layout
  473.           fi
  474.           $_cmd $_cmd_opts $_dir || warn "$_cmd $_cmd_opts $_dir" \
  475.                               "failed; font directory data may not" \
  476.                               "be up to date"
  477.         else
  478.           warn "$_cmd not found; not updating corresponding $_dir font" \
  479.                "directory data"
  480.         fi
  481.       done
  482.     else
  483.       warn "$_dir is not a directory; not updating font directory data"
  484.     fi
  485.   done
  486. }
  487.  
  488. remove_conffile_prepare () {
  489.   # syntax: remove_conffile_prepare filename official_md5sum ...
  490.   #
  491.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  492.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  493.   # operands provided, then prepare the conffile for removal from the system.
  494.   # We defer actual deletion until the package is configured so that we can
  495.   # roll this operation back if package installation fails.
  496.   #
  497.   # Call this function from a preinst script in the event $1 is "upgrade" or
  498.   # "install" and verify $2 to ensure the package is being upgraded from a
  499.   # version (or installed over a version removed-but-not-purged) prior to the
  500.   # one in which the conffile was obsoleted.
  501.  
  502.   #local conffile current_checksum
  503.  
  504.   # validate arguments
  505.   if [ $# -lt 2 ]; then
  506.     usage_error "remove_conffile_prepare() called with wrong number of" \
  507.                 "arguments; expected at least 2, got $#"
  508.     exit $SHELL_LIB_USAGE_ERROR
  509.   fi
  510.  
  511.   _conffile="$1"
  512.   shift
  513.  
  514.   # does the _conffile even exist?
  515.   if [ -e "$_conffile" ]; then
  516.     # calculate its checksum
  517.     _current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
  518.     # compare it to each supplied checksum
  519.     while [ -n "$1" ]; do
  520.       if [ "$_current_checksum" = "$1" ]; then
  521.         # we found a match; move the confffile and stop looking
  522.         observe "preparing obsolete conffile $_conffile for removal"
  523.         mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
  524.         break
  525.       fi
  526.       shift
  527.     done
  528.   fi
  529. }
  530.  
  531. remove_conffile_commit () {
  532.   # syntax: remove_conffile_commit filename
  533.   #
  534.   # Complete the removal of a conffile "filename" that has become obsolete.
  535.   #
  536.   # Call this function from a postinst script after having used
  537.   # remove_conffile_prepare() in the preinst.
  538.  
  539.   #local conffile
  540.  
  541.   # validate arguments
  542.   if [ $# -ne 1 ]; then
  543.     usage_error "remove_conffile_commit() called with wrong number of" \
  544.                 "arguments; expected 1, got $#"
  545.     exit $SHELL_LIB_USAGE_ERROR
  546.   fi
  547.  
  548.   _conffile="$1"
  549.  
  550.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  551.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  552.     observe "committing removal of obsolete conffile $_conffile"
  553.     rm "$_conffile.$THIS_PACKAGE-tmp"
  554.   fi
  555. }
  556.  
  557. remove_conffile_rollback () {
  558.   # syntax: remove_conffile_rollback filename
  559.   #
  560.   # Roll back the removal of a conffile "filename".
  561.   #
  562.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  563.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  564.   # preinst.
  565.  
  566.   #local conffile
  567.  
  568.   # validate arguments
  569.   if [ $# -ne 1 ]; then
  570.     usage_error "remove_conffile_rollback() called with wrong number of" \
  571.                 "arguments; expected 1, got $#"
  572.     exit $SHELL_LIB_USAGE_ERROR
  573.   fi
  574.  
  575.   _conffile="$1"
  576.  
  577.   # if the temporary file created by remove_conffile_prepare() exists, move it
  578.   # back
  579.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  580.     observe "rolling back removal of obsolete conffile $_conffile"
  581.     mv "$_conffile.$THIS_PACKAGE-tmp" "$_conffile"
  582.   fi
  583. }
  584.  
  585. replace_conffile_with_symlink_prepare () {
  586.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  587.   # official_md5sum ...
  588.   #
  589.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  590.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  591.   # operands provided, then prepare the conffile for removal from the system.
  592.   # We defer actual deletion until the package is configured so that we can
  593.   # roll this operation back if package installation fails. Otherwise copy it
  594.   # to newfilename and let dpkg handle it through conffiles mechanism.
  595.   #
  596.   # Call this function from a preinst script in the event $1 is "upgrade" or
  597.   # "install" and verify $2 to ensure the package is being upgraded from a
  598.   # version (or installed over a version removed-but-not-purged) prior to the
  599.   # one in which the conffile was obsoleted.
  600.  
  601.   #local conffile current_checksum
  602.  
  603.   # validate arguments
  604.   if [ $# -lt 3 ]; then
  605.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  606.                 " number of arguments; expected at least 3, got $#"
  607.     exit $SHELL_LIB_USAGE_ERROR
  608.   fi
  609.  
  610.   _oldconffile="$1"
  611.   shift
  612.   _newconffile="$1"
  613.   shift
  614.  
  615.   remove_conffile_prepare "$_oldconffile" "$@"
  616.   # If $_oldconffile still exists, then md5sums didn't match.
  617.   # Copy it to new one.
  618.   if [ -f "$_oldconffile" ]; then
  619.     cp "$_oldconffile" "$_newconffile"
  620.   fi
  621.  
  622. }
  623.  
  624. replace_conffile_with_symlink_commit () {
  625.   # syntax: replace_conffile_with_symlink_commit oldfilename
  626.   #
  627.   # Complete the removal of a conffile "oldfilename" that has been
  628.   # replaced by a symlink.
  629.   #
  630.   # Call this function from a postinst script after having used
  631.   # replace_conffile_with_symlink_prepare() in the preinst.
  632.  
  633.   #local conffile
  634.  
  635.   # validate arguments
  636.   if [ $# -ne 1 ]; then
  637.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  638.                 "number of arguments; expected 1, got $#"
  639.     exit $SHELL_LIB_USAGE_ERROR
  640.   fi
  641.  
  642.   _conffile="$1"
  643.  
  644.   remove_conffile_commit "$_conffile"
  645. }
  646.  
  647. replace_conffile_with_symlink_rollback () {
  648.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  649.   #
  650.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  651.   # "newfilename".
  652.   #
  653.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  654.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  655.   # from a version (or install over a version removed-but-not-purged) prior
  656.   # to the one in which the conffile was obsoleted.
  657.   # You should have  used replace_conffile_with_symlink_prepare() in the
  658.   # preinst.
  659.  
  660.   #local conffile
  661.  
  662.   # validate arguments
  663.   if [ $# -ne 2 ]; then
  664.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  665.                 "number of arguments; expected 2, got $#"
  666.     exit $SHELL_LIB_USAGE_ERROR
  667.   fi
  668.  
  669.   _oldconffile="$1"
  670.   _newconffile="$2"
  671.  
  672.   remove_conffile_rollback "$_oldconffile"
  673.   if [ -f "$_newconffile" ]; then
  674.     rm "$_newconffile"
  675.   fi
  676. }
  677.  
  678. run () {
  679.   # syntax: run command [ argument ... ]
  680.   #
  681.   # Run specified command with optional arguments and report its exit status.
  682.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  683.   # or commands whose failure is not fatal to us.
  684.   #
  685.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  686.   # those cases the return value of the debconf command *must* be checked
  687.   # before the string returned by debconf is used for anything.
  688.  
  689.   #local retval
  690.  
  691.   # validate arguments
  692.   if [ $# -lt 1 ]; then
  693.     usage_error "run() called with wrong number of arguments; expected at" \
  694.                 "least 1, got $#"
  695.     exit $SHELL_LIB_USAGE_ERROR
  696.   fi
  697.  
  698.   "$@" || _retval=$?
  699.  
  700.   if [ ${_retval:-0} -ne 0 ]; then
  701.     observe "command \"$*\" exited with status $_retval"
  702.   fi
  703. }
  704.  
  705. register_x_lib_dir_with_ld_so () {
  706.   # syntax: register_x_lib_dir_with_ld_so
  707.   #
  708.   # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
  709.   # libraries.
  710.   #
  711.   # Call this function from the postinst script of a package that places a
  712.   # shared library in /usr/X11R6/lib, before invoking ldconfig.
  713.  
  714.   #local dir ldsoconf
  715.  
  716.   _dir="/usr/X11R6/lib"
  717.   _ldsoconf="/etc/ld.so.conf"
  718.  
  719.   # is the line not already present?
  720.   if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
  721.     observe "adding $_dir directory to $_ldsoconf"
  722.     echo "$_dir" >> "$_ldsoconf"
  723.   fi
  724. }
  725.  
  726. deregister_x_lib_dir_with_ld_so () {
  727.   # syntax: deregister_x_lib_dir_with_ld_so
  728.   #
  729.   # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
  730.   # libraries, if and only if no shared libaries remain there.
  731.   #
  732.   # Call this function from the postrm script of a package that places a shared
  733.   # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
  734.   # invoking ldconfig.
  735.  
  736.   #local dir ldsoconf fgrep_status cmp_status
  737.  
  738.   _dir="/usr/X11R6/lib"
  739.   _ldsoconf="/etc/ld.so.conf"
  740.  
  741.   # is the line present?
  742.   if fgrep -qsx "$_dir" "$_ldsoconf"; then
  743.     # are there any shared objects in the directory?
  744.     if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
  745.       # glob expansion produced nothing, so no shared libraries are present
  746.       observe "removing $_dir directory from $_ldsoconf"
  747.       # rewrite the file (very carefully)
  748.       set +e
  749.       fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
  750.       _fgrep_status=$?
  751.       set -e
  752.       case $_fgrep_status in
  753.         0|1) ;; # we don't actually care if any lines matched or not
  754.         *) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
  755.           "$_fgrep_status" ;;
  756.       esac
  757.       set +e
  758.       cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
  759.       _cmp_status=$?
  760.       set -e
  761.       case $_cmp_status in
  762.         0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
  763.         1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
  764.         *) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
  765.           "cmp exited with status $_cmp_status" ;;
  766.       esac
  767.     fi
  768.   fi
  769. }
  770.  
  771. make_symlink_sane () {
  772.   # syntax: make_symlink_sane symlink target
  773.   #
  774.   # Ensure that the symbolic link symlink exists, and points to target.
  775.   #
  776.   # If symlink does not exist, create it and point it at target.
  777.   #
  778.   # If symlink exists but is not a symbolic link, back it up.
  779.   #
  780.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  781.   # it.
  782.   #
  783.   # If symlink exists, is a symbolic link, and already points to target, do
  784.   # nothing.
  785.   #
  786.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  787.  
  788.   # Validate arguments.
  789.   if [ $# -ne 2 ]; then
  790.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  791.       "expected 2, got $#"
  792.     exit $SHELL_LIB_USAGE_ERROR
  793.   fi
  794.  
  795.   # We could just use the positional parameters as-is, but that makes things
  796.   # harder to follow.
  797.   #local symlink target
  798.  
  799.   _symlink="$1"
  800.   _target="$2"
  801.  
  802.   if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
  803.       observe "link from $_symlink to $_target already exists"
  804.   else
  805.     observe "creating symbolic link from $_symlink to $_target"
  806.     mkdir -p "${_target%/*}" "${_symlink%/*}"
  807.     ln -s -b -S ".dpkg-old" "$_target" "$_symlink"
  808.   fi
  809. }
  810.  
  811. migrate_dir_to_symlink () {
  812.   # syntax: migrate_dir_to_symlink old_location new_location
  813.   #
  814.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  815.   # symbolic link to a directory or vice versa; instead, the existing state
  816.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  817.   # there is one."
  818.   #
  819.   # We have to do it ourselves.
  820.   #
  821.   # This function moves the contents of old_location, a directory, into
  822.   # new_location, a directory, then makes old_location a symbolic link to
  823.   # new_location.
  824.   #
  825.   # old_location need not exist, but if it does, it must be a directory (or a
  826.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  827.   # exists already and is not a directory, it is backed up.
  828.   #
  829.   # This function should be called from a package's preinst so that other
  830.   # packages unpacked after this one --- but before this package's postinst runs
  831.   # --- are unpacked into new_location even if their payloads contain
  832.   # old_location filespecs.
  833.  
  834.   # Validate arguments.
  835.   if [ $# -ne 2 ]; then
  836.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  837.                 "arguments; expected 2, got $#"
  838.     exit $SHELL_LIB_USAGE_ERROR
  839.   fi
  840.  
  841.   # We could just use the positional parameters as-is, but that makes things
  842.   # harder to follow.
  843.   local _new _old
  844.  
  845.   _old="$1"
  846.   _new="$2"
  847.  
  848.   # Is old location a symlink?
  849.   if [ -L "$_old" ]; then
  850.     # Does it already point to new location?
  851.     if [ "$(readlink "$_old")" = "$_new" ]; then
  852.       # Nothing to do; migration has already been done.
  853.       observe "migration of $_old to $_new already done"
  854.       return 0
  855.     else
  856.       # Back it up.
  857.       warn "backing up symbolic link $_old as $_old.dpkg-old"
  858.       mv -b "$_old" "$_old.dpkg-old"
  859.     fi
  860.   fi
  861.  
  862.   # Does old location exist, but is not a directory?
  863.   if [ -e "$_old" ] && ! [ -d "$_old" ]; then
  864.       # Back it up.
  865.       warn "backing up non-directory $_old as $_old.dpkg-old"
  866.       mv -b "$_old" "$_old.dpkg-old"
  867.   fi
  868.  
  869.   observe "migrating $_old to $_new"
  870.  
  871.   # Is new location a symlink?
  872.   if [ -L "$_new" ]; then
  873.     # Does it point the wrong way, i.e., back to where we're migrating from?
  874.     if [ "$(readlink "$_new")" = "$_old" ]; then
  875.       # Get rid of it.
  876.       observe "removing symbolic link $_new which points to $_old"
  877.       rm "$_new"
  878.     else
  879.       # Back it up.
  880.       warn "backing up symbolic link $_new as $_new.dpkg-old"
  881.       mv -b "$_new" "$_new.dpkg-old"
  882.     fi
  883.   fi
  884.  
  885.   # Does new location exist, but is not a directory?
  886.   if [ -e "$_new" ] && ! [ -d "$_new" ]; then
  887.     warn "backing up non-directory $_new as $_new.dpkg-old"
  888.     mv -b "$_new" "$_new.dpkg-old"
  889.   fi
  890.  
  891.   # Create new directory if it does not yet exist.
  892.   if ! [ -e "$_new" ]; then
  893.     observe "creating $_new"
  894.     mkdir -p "$_new"
  895.   fi
  896.  
  897.   # Copy files in old location to new location.  Back up any filenames that
  898.   # already exist in the new location with the extension ".dpkg-old".
  899.   observe "copying files from $_old to $_new"
  900.   if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
  901.     die "error(s) encountered while copying files from $_old to $_new"
  902.   fi
  903.  
  904.   # Remove files at old location.
  905.   observe "removing $_old"
  906.   rm -r "$_old"
  907.  
  908.   # Create symlink from old location to new location.
  909.   make_symlink_sane "$_old" "$_new"
  910. }
  911.  
  912. # vim:set ai et sw=2 ts=2 tw=80:
  913.  
  914. # GOBSTOPPER: The X Strike Force shell library ends here.
  915.  
  916. if [ -d /usr/share/X11/fonts ]; then
  917.     find /usr/share/X11/fonts -type f -name fonts.cache-1 -print0 | xargs -0r rm -f
  918.     find /usr/share/X11/fonts -type d -empty -delete || true
  919.     for dir in $(find /usr/share/X11/fonts -mindepth 1 -type d); do
  920.     if [ -z "$(find $dir -not -name fonts.dir -and -not -name fonts.scale \
  921.                  -and -not -name fonts.alias)" ]; then
  922.         rm -rf $dir
  923.     fi
  924.     done
  925. fi
  926.  
  927.  
  928.  
  929. exit 0
  930.